package com.zhang.family_doctor.controller;

import com.zhang.family_doctor.entity.R;
import com.zhang.family_doctor.entity.Treaty;
import com.zhang.family_doctor.service.TreatyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 协议管理
 */
@Api(tags = "协议管理相关接口")
@RestController
@RequestMapping("/treaty")
@Slf4j
public class TreatyController {

    @Autowired
    private TreatyService treatyService;

    @ApiOperation("新增或修改")
    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody Treaty treaty, HttpServletRequest request){
        log.info("新增或修改：{}",treaty);
        return treatyService.saveOrUpdate(treaty,request);
    }

    @ApiOperation("根据协议类型查询协议")
    @GetMapping("/getTreatyByAgreementType")
    public R getTreatyByAgreementType(@RequestParam(value = "agreementType",required = false) Integer agreementType){
        log.info("根据协议类型查询协议：{}",agreementType);
        return treatyService.getTreatyByAgreementType(agreementType);
    }

}
